<template>
    <view class="p_20">
        <view v-for="(item,index) in goodsListData" :key="index" >
            <view @click="handleToInfo(item)">
                <view class="dis_f_sb">
                    <view>
                        <view class="dis_f_l">
                            {{item.bt}}
                        </view>

                        <view class="c_9 m_t_10 m_b_10 f_s_14 over2">{{item.nr}}</view>
                    </view>
                    <u-image :src="item.photoUrl"  v-if="item.isImg||!item.photoUrl" width="200rpx" height="200rpx"></u-image>
                    <view  v-else>
                    <video  :src="item.photoUrl" style="width: 200rpx;height:200rpx;object-fit: fill"></video>
                    </view>
                </view>
                <view class="dis_f_l_c m_b_20">
                    <u-icon name="map" ></u-icon>
                    <view class="m_l_5 c_9 f_s_12">{{item.province}}{{item.city}}{{item.districts}}</view>
                </view>
                <view v-if="isReject&&item.shly&&item.shzt!=2" class="c_red f_s_12 dis_f_r_c">
                    驳回理：{{item.shly}}
                </view>
            </view>
<!--            <view class="dis_f_r_c" v-if="isLike">
                <u-icon v-if="item.sfxh" name="heart-fill" size="30" color="red" @click="handleLike(item)"></u-icon>
                <u-icon v-else name="heart" size="30"   @click="handleLike(item)"></u-icon>
            </view>-->
            <view v-if="isToUp&&item.shzt==2" class="dis_f_r_c">
                <view>
                    <u-button type="success" size="small" @click="handleToUp(item)">刷新</u-button>
                </view>
            </view>
            <view class="dis_f_r_c m_t_10" v-if="isExamine&&item.shzt!=2">
                <view class="m_r_10">
                    <u-button type="error" shape="circle" size="mini" @click="handleShowReject(item)">驳回</u-button>
                </view>
                <view>
                    <u-button type="primary" shape="circle" size="mini" color="#27AC2F" @click="handlePass(item)">通过</u-button>
                </view>
            </view>
            <u-divider></u-divider>
        </view>
        <view class="">
        <u-modal  :show="showExamine" title="信息审核" showCancelButton @cancel="showExamine=false" @confirm="handleReject">
            <view  class="sh_box">
            <u--form

                labelPosition="top"
                labelWidth="auto"
            >
                <u-form-item
                    label="驳回原因"
                    ref="item1"
                >
                    <u--textarea   v-model="dataReview.shly" placeholder="请输入驳回原因"></u--textarea >
                </u-form-item>
            </u--form>
            </view>
        </u-modal>
            <u-modal  :show="showRefresh" title="刷新方式" showCancelButton @cancel="showRefresh=false" @confirm="handleRefresh">
            <view  class="sh_box">
                <u-radio-group v-model="refreshType">
                    <u-radio :name="2" label="每日次数"></u-radio>
                    <view class="m_l_10">
                    <u-radio :name="1" label="积分兑换次数"></u-radio>
                    </view>
                </u-radio-group>
            </view>
        </u-modal>
    </view>
    </view>
</template>
<script>
import {informationRefreshApi, reviewAdvertisementsApi} from "@/sheep/api";

export default {
    name: "index",
    props: {
        goodsList: {
            type: Array,
            default: []
        },
        isLike: {
            type: Boolean,
            default: false
        },
        isReject: {
            type: Boolean,
            default: false
        },
        isToUp: {
            type: Boolean,
            default: false
        },
        isExamine: {
            type: Boolean,
            default: false
        },
        isExaminePeople: {
            type: Boolean,
            default: false
        }
    },
    data() {
        return {
            refreshType:'',
            refreshId:'',
            showRefresh:false,
            showExamine:false,
            dataReview:{
                shzt:3,
                shly:''
            },
            goodsListData:this.goodsList||[],
        }
    },
    watch: {
        goodsList(curVal) {
            this.goodsListData=[]
            if (curVal.length>0){
                this.goodsListData = curVal
                for (let i = 0; i <curVal.length; i++) {
                    this.$set(this.goodsListData[i], 'isImg', true)
                    if (curVal[i].photoUrl){
                        this.goodsListData[i].photoUrl = curVal[i].photoUrl.split(',')[0]
                        if (this.goodsListData[i].photoUrl .indexOf('mp4')>-1){
                            this.goodsListData[i].isImg = false
                        }

                    }
                }
            }
        }
    },
    methods:{
        handleToInfo(item){
            uni.navigateTo({
                url: '/pages/index/info?goodsId='+item.id+'&isExaminePeople='+this.isExaminePeople
            })
        },
        handleLike(item){
            this.$emit('handleLike',item)
        },
        handleToUp(item){
            this.refreshId = item.id
            this.showRefresh=true
        },
        handleRefresh(){
            if (!this.refreshType){
                uni.showToast({
                    title: '请选择刷新方式',
                    icon: "none",
                    duration: 2000
                })
                return
            }
            informationRefreshApi({id:this.refreshId,type:this.refreshType}).then(res=>{
                uni.showToast({
                    title: res.msg,
                    icon: "none",
                    duration: 2000
                })
                if (res.code==200){
                    this.refreshType=''
                    this.refreshId=''
                    this.showRefresh=false
                    this.$emit('updataData')
                }
            })
        },
        handleShowReject(item){
            this.dataReview.id=item.id
            this.showExamine=true
        },
        handleReject(){
            if (!this.dataReview.shly){
                uni.showToast({
                    title: '请输入驳回原因',
                    icon: 'none'
                })
                return
            }
            reviewAdvertisementsApi(this.dataReview).then(res=>{
                uni.showToast({
                    title: res.msg,
                    icon: 'none'
                })
                if (res.code==200){
                    this.dataReview.shly=''
                    this.showExamine=false
                    this.$emit('updataData')
                }
            })
        },
        handlePass(item){
            uni.showModal({
                title: '提示',
                content: '确定通过吗？',
                success: (res) => {
                    if (!res.confirm){
                        return
                    }
                    reviewAdvertisementsApi({id:item.id,shzt:2}).then(res=>{
                        uni.showToast({
                            title: res.msg,
                            icon: 'none'
                        })
                        if (res.code==200){
                            this.showExamine=false
                            this.$emit('updataData')
                        }
                    })
                }
            })
        },
    }
}
</script>

<style lang="scss">
.sh_box{
    width: 100%;
}

</style>
